package xkp.lesson.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import xkp.lesson.entity.Emp;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/emp")
public class EmpController {

    @ResponseBody
    @GetMapping("/getEmp/{id}/{name}")
    public Emp getEmp(@PathVariable("id") Integer id, @PathVariable("name") String name){
        Emp emp = new Emp();
        emp.setEmpno(id);
        emp.setEname(name);
        return  emp;
    }

    @ResponseBody
    @GetMapping("/selectAll")
    public List<Emp> selectAll(){
       List<Emp> empList = new ArrayList<Emp>();
       for(int i = 1;i <= 10; i++){
           Emp emp = new Emp();
           emp.setEmpno(i);
           emp.setEname("emp"+i);
           empList.add(emp);
       }
       return empList;
    }

    @ResponseBody
    @GetMapping("/selectById/{id}")
    public Emp selectById(@PathVariable("id") int id){
        Emp emp = new Emp();
        emp.setEmpno(id);
        return emp;
    }

    @ResponseBody
    @PostMapping("/insertEmp")
    public Emp insertEmp(@RequestBody Emp emp){
        return emp;
    }

    @ResponseBody
    @DeleteMapping("/deleteEmp/{id}")
    public Emp deleteEmp(@PathVariable("id") int id){
        Emp emp = new Emp();
        emp.setEmpno(id);
        return emp;
    }

    @ResponseBody
    @PutMapping("/updateEmp")
    public Emp deleteEmp(@RequestBody Emp emp){
        return emp;
    }
}
